local que_guichao = fk.CreateSkill {
    name = "que_guichao",
    tags = { Skill.Compulsory }
}
Fk:loadTranslationTable {
    ["que_guichao"] = "归潮",
    [":que_guichao"] = "锁定技，你的首个回合开始时，你可以选择至多两名其他角色，各获得其武将牌的一个随机<a href='pt_skills'>普通技能</a>，每回合限两次，发动因此获得的技能后，你摸一张牌；你每受到两次伤害，随机失去一个其他技能。",

    ["pt_skills"] = "觉醒技，限定技，隐匿技，持恒技，主公技，蓄力技，宗族技外的其他技能类型",

    ["@que_guichao"] = "",
}
que_guichao:addEffect(fk.EventPhaseStart, {
    anim_type = "support",
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(que_guichao.name) and player.phase == Player.Start and
            player:usedEffectTimes(que_guichao.name, Player.HistoryGame) == 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local tos = room:askToChoosePlayers(player, {
            skill_name = que_guichao.name,
            min_num = 1,
            max_num = 2,
            targets = room:getOtherPlayers(player),
            prompt = "归潮：你可以选择至多两名角色，获得其随机一个技能",
            cancelable = false,
        })
        if #tos > 0 then
            room:sortByAction(tos)
            event:setCostData(self, { tos = tos })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local skilltype = { Skill.Limited, Skill.Wake, Skill.Permanent, Skill.Lord, Skill.Hidden,
            Skill.Charge, Skill.Family }
        local to1 = event:getCostData(self).tos[1]
        local skill_give
        local skills = {}
        for _, s in ipairs(to1:getSkillNameList()) do
            local skill = Fk.skills[s]
            if skill.visible and not (skill:hasTag(Skill.Limited) or skill:hasTag(Skill.Wake) or skill:hasTag(Skill.Permanent) or skill:hasTag(Skill.Lord) or skill:hasTag(Skill.Hidden)
                    or skill:hasTag(Skill.Charge) or skill:hasTag(Skill.Family)) and not player:hasSkill(skill) and skill:isPlayerSkill(to1) then
                table.insertIfNeed(skills, s)
            end
        end
        if #skills > 0 then
            skill_give = table.random(skills)
            room:handleAddLoseSkills(player, skill_give)
            room:addTableMarkIfNeed(player, "@que_guichao", skill_give)
        end
        if #event:getCostData(self).tos > 1 then
            local to2 = event:getCostData(self).tos[2]
            skills = {}
            for _, s in ipairs(to2:getSkillNameList()) do
                local skill = Fk.skills[s]
                if skill.visible and not (skill:hasTag(Skill.Limited) or skill:hasTag(Skill.Wake) or skill:hasTag(Skill.Permanent) or skill:hasTag(Skill.Lord) or skill:hasTag(Skill.Hidden)
                        or skill:hasTag(Skill.Charge) or skill:hasTag(Skill.Family)) and not player:hasSkill(skill) and skill:isPlayerSkill(to1) then
                    table.insertIfNeed(skills, s)
                end
            end
            if #skills > 0 then
                skill_give = table.random(skills)
                room:handleAddLoseSkills(player, skill_give)
                room:addTableMarkIfNeed(player, "@que_guichao", skill_give)
            end
        end
        room:setPlayerMark(player, "guichao", 1)
    end,
})
que_guichao:addEffect(fk.Damaged, {
    anim_type = "masochism",
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player:getMark("guicao_damage") > 1
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player, "guicao_damage", 0)
        local skills = {}
        for _, s in ipairs(player:getSkillNameList()) do
            local skill = Fk.skills[s]
            if skill.name ~= "que_guichao" then
                table.insertIfNeed(skills, s)
            end
        end
        if #skills > 0 then
            local skill = table.random(skills)
            room:handleAddLoseSkills(player, "-" .. skill)
            room:removeTableMark(player, "@que_guichao", skill)
        end
    end,


    can_refresh = function(self, event, target, player, data)
        return target == player and player:hasSkill(que_guichao.name, true)
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:addPlayerMark(player, "guicao_damage")
    end,
})

que_guichao:addEffect(fk.AfterSkillEffect, {
    anim_type = "drawcard",
    mute = true,
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        local mark = player:getTableMark("@que_guichao")
        return #mark ~= 0 and player:hasSkill(que_guichao.name) and target == player and
            table.contains(mark, data.skill.name) and player:usedEffectTimes(que_guichao.name, Player.HistoryGame) < 2
    end,
    on_use = function(self, event, target, player, data)
        player:drawCards(1, que_guichao.name)
    end,
})

return que_guichao
